/*    */ package com.equipmentmanage.dao.impl;
/*    */ 
/*    */ import com.equipmentmanage.dao.EquipmentTypeDao;
import com.equipmentmanage.model.EquipmentType;
import com.equipmentmanage.model.PageBean;
import com.equipmentmanage.util.StringUtil;

/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import javax.annotation.Resource;
/*    */ import org.springframework.jdbc.core.JdbcTemplate;
/*    */ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;
/*    */ 
/*    */ @Repository("equipmentTypeDao")
/*    */ public class EquipmentTypeDaoImpl
/*    */   implements EquipmentTypeDao
/*    */ {
/*    */ 
/*    */   @Resource
/*    */   private JdbcTemplate jdbcTemplate;
/*    */ 
/*    */   public void add(EquipmentType equipmentType)
/*    */   {
/* 31 */     String sql = "insert into t_equipmentType values(null,?,?)";
/* 32 */     this.jdbcTemplate.update(sql, new Object[] { equipmentType.getTypeName(), equipmentType.getRemark() });
/*    */   }
/*    */ 
/*    */   public void update(EquipmentType equipmentType) {
/* 36 */     String sql = "update t_equipmentType set typeName=?,remark=? where id=? ";
/* 37 */     this.jdbcTemplate.update(sql, new Object[] { equipmentType.getTypeName(), equipmentType.getRemark(), equipmentType.getId() });
/*    */   }
/*    */ 
/*    */   public void delete(int id) {
/* 41 */     String sql = "delete from t_equipmentType where id=?";
/* 42 */     this.jdbcTemplate.update(sql, new Object[] { Integer.valueOf(id) });
/*    */   }
/*    */ 
/*    */   public List<EquipmentType> find(PageBean pageBean, EquipmentType s_equipmentType)
/*    */   {
/* 47 */     StringBuffer sb = new StringBuffer("select * from t_equipmentType");
/* 48 */     if ((s_equipmentType != null) && 
/* 49 */       (StringUtil.isNotEmpty(s_equipmentType.getTypeName()))) {
/* 50 */       sb.append(" and typeName like '%" + s_equipmentType.getTypeName() + "%'");
/*    */     }
/*    */ 
/* 53 */     if (pageBean != null) {
/* 54 */       sb.append(" limit " + pageBean.getStart() + "," + pageBean.getPageSize());
/*    */     }
/* 56 */     final List equipmentList = new ArrayList();
/* 57 */     this.jdbcTemplate.query(sb.toString().replaceFirst("and", "where"), new Object[0], new RowCallbackHandler()
/*    */     {
/*    */       public void processRow(ResultSet rs) throws SQLException
/*    */       {
/* 61 */         EquipmentType equipmentType = new EquipmentType();
/* 62 */         equipmentType.setId(Integer.valueOf(rs.getInt("id")));
/* 63 */         equipmentType.setTypeName(rs.getString("typeName"));
/* 64 */         equipmentType.setRemark(rs.getString("remark"));
/* 65 */         equipmentList.add(equipmentType);
/*    */       }
/*    */     });
/* 68 */     return equipmentList;
/*    */   }
/*    */ 
/*    */   public int count(EquipmentType s_equipmentType) {
/* 72 */     StringBuffer sb = new StringBuffer("select count(*) from t_equipmentType");
/* 73 */     if ((s_equipmentType != null) && 
/* 74 */       (StringUtil.isNotEmpty(s_equipmentType.getTypeName()))) {
/* 75 */       sb.append(" and typeName like '%" + s_equipmentType.getTypeName() + "%'");
/*    */     }
/*    */ 
/* 78 */     return ((Integer)this.jdbcTemplate.queryForObject(sb.toString().replaceFirst("and", "where"), Integer.class)).intValue();
/*    */   }
/*    */ 
/*    */   public EquipmentType loadById(int id) {
/* 82 */     String sql = "select * from t_equipmentType where id=? ";
/* 83 */     final EquipmentType equipmentType = new EquipmentType();
/* 84 */     this.jdbcTemplate.query(sql, new Object[] { Integer.valueOf(id) }, new RowCallbackHandler()
/*    */     {
/*    */       public void processRow(ResultSet rs) throws SQLException
/*    */       {
/* 88 */         equipmentType.setId(Integer.valueOf(rs.getInt("id")));
/* 89 */         equipmentType.setTypeName(rs.getString("typeName"));
/* 90 */         equipmentType.setRemark(rs.getString("remark"));
/*    */       }
/*    */     });
/* 93 */     return equipmentType;
/*    */   }
/*    */ }

/* Location:           C:\Users\arcgis\Desktop\新建文件夹\a0\[www.java1234.com]《SpringMvc设备管理系统》第零讲源码及文档\EquipmentSys\WEB-INF\classes\
 * Qualified Name:     com.java1234.dao.impl.EquipmentTypeDaoImpl
 * JD-Core Version:    0.6.1
 */